package wcm;

import wcm.test.RobotTestBed;
import robocode.control.events.RoundEndedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IRobotSnapshot;
import static org.junit.Assert.assertTrue;

/**
 * Tests whether Bato is too close to the enemy robot.
 * @author wing
 *
 */
public class TestBato3 extends RobotTestBed {

  Boolean tooClose = false;
  
  /**
   * Specifies that SittingDuck and Bato are to be matched up in this test case.
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.SittingDuck,wcm.Bato";
  }
  
  /**
   * This test runs for 10 rounds.
   * @return The number of rounds. 
   */
  @Override
  public int getNumRounds() {
    return 10;
  }
  
  /** 
   * Calculate the distance between the two robots.
   * @param event Details about the completed battle.
   */
  @Override
  public void onTurnEnded(TurnEndedEvent event) {
    
    tooClose = false;
    IRobotSnapshot me = event.getTurnSnapshot().getRobots()[1];
    IRobotSnapshot enemy = event.getTurnSnapshot().getRobots()[0];
    
    double positionMeY = me.getY();
    double positionMeX = me.getX();
    
    double positionEnemyY = enemy.getY();
    double positionEnemyX = enemy.getX();
    
    //calculate distance from each other
    double sumX = Math.abs(positionEnemyX - positionMeX);
    double sumY = Math.abs(positionEnemyY - positionMeY);
    
    double pythDistance = Math.sqrt(Math.pow(sumX, 2) + Math.pow(sumY, 2));
    
    if (pythDistance <= 20) {
      tooClose = true;
    }
    
    
  }
  
  /** 
   * Checks if there has been a case where a robot has been too close.
   * @param event Details about the completed battle.
   */
  @Override
  public void onRoundEnded(RoundEndedEvent event) {
    
    assertTrue("Retaliation", !tooClose);
    
  }
  
  
  
}
